<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\admin\controller;
use App\AccountLog;
use app\common\model\AppAccountLog;
use app\common\model\ApplicationOrder;
use app\common\model\ThirdApplicationResultLog;

use think\Db;



/**
 * 倍投控制器
 */
class FakeDataTemplate extends AdminBase
{

    public function FakeDataTemplateList()
    {
        $where = $this->logicFakeDataTemplate->getWhere($this->param);
        $this->assign('product',Db::name("gambler_king_investment")->where("1=1")->select());
        $this->assign('list', $this->logicFakeDataTemplate->getFakeDataTemplateList($where, 'a.*', 'a.create_time asc'));
        return $this->fetch('fakedata_template_list');
    }

    public function fakeDataTemplateEdit(){
        $this->assign('product',Db::name("gambler_king_investment")->where("1=1")->select());
        if(IS_POST){
            $arr = array();
            foreach($this->param["king"] as $k=>$v){
                $arr[$k]['king']=$v;
                $arr[$k]["product_id"]=$this->param['product_id'][$k];
                $arr[$k]["user_name"]=$this->param['user_name'][$k];
                $arr[$k]["money"]=$this->param['money'][$k];
                $arr[$k]['percent']=$this->param["percent"][$k];
                $arr[$k]['win_count']=$this->param['win_count'][$k];
                $arr[$k]['loss_count']=$this->param['loss_count'][$k];
                $arr[$k]['draw_count']=$this->param['draw_count'][$k];
            }
            $data = json_encode($arr);
            Db::startTrans();
            try{
                Db::name("fake_data_template")->where(["id"=>$this->param["id"]])->update(["name"=>$this->param["template_name"],"data"=>$data]);
                Db::commit();
            }catch(\Exception $e){
                Db::rollback();
                $this->error("修改失败".$e->getMessage());
            }
            $this->success("修改成功");
        }else{
            $id = $this->param["id"];
            $data = Db::name("fake_data_template")->where(["id"=>$id])->find();
            $data["data"]=json_decode($data["data"],true);
            $this->assign("data",$data);
            
            return $this->fetch("fakedata_template_edit");
        }
        
    }

}
